<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="农资名称" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="登记证号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="农资分类" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.typeFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产厂家" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.manufacturer }}</span>
        </template>
      </el-table-column>
      <el-table-column label="规格" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.specifications }}</span>
        </template>
      </el-table-column>
      <el-table-column label="库存量" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.remainingQuantity }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" :disabled="addBtnDisabled(scope.row.agriDicId)" @click="handleEdit(scope.row)"
            >选择</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="2"
        layout="prev, pager, next, jumper"
        :total="dialogTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getFarmsStockInventoryApi
} from '@/api/mission'
export default {
  name: 'SevencolorUserFarmStockDialog',
  props: {
    farmStockList: {
      type: Array
    },
    total: {
      type: Number
    },
    farmStockAddList: {
      type: Array
    }
  },

  data () {
    return {
      currentPage: 1,
      tableData: [],
      dialogTotal: null,
      params: {
        current: 1,
        pageSize: 2
      }
    }
  },

  mounted () {
    this.tableData = this.farmStockList
    this.dialogTotal = this.total
  },

  methods: {
    // 按钮禁用判断
    addBtnDisabled (id) {
      // console.log(id)
      // console.log(this.farmStockAddList)
      for (let i = 0; i < this.farmStockAddList.length; i++) {
        if (this.farmStockAddList[i].agriId === id) {
          return true
        }
      }
      return false
    },
    // 选中
    handleEdit (val) {
      this.$emit('addFarmStock', val)
      this.params.current = 1
    },
    async handleCurrentChange (val) {
      console.log(val)
      this.params.current = val
      const res = await getFarmsStockInventoryApi(this.params)
      this.tableData = res.data.records
      this.dialogTotal = res.data.total
    }
  }
}
</script>
<style lang="scss" scoped>
.pagination {
  margin: 2vw 35%;
  ::v-deep .el-input__inner {
  width: 0.5rem !important;
}
}

</style>
